#include "com_wiseman_jxgl_Util.h"
#include <jni.h>
#include <stdio.h>
#include <string.h>
/*
 * Class:     com_wiseman_jxgl_Util
 * Method:    checkRegister
 * Signature: (JJ)I
 */
JNIEXPORT jboolean JNICALL Java_com_wiseman_jxgl_Util_checkRegister(JNIEnv *env,
		jclass cls, jstring imei, jlong regcode) {

	long  code1 = 19790314;
	long  code2 = 19811101;
	long  code3 = 20070828;
	const char *strIMEI = env->GetStringUTFChars(imei, 0);
	int i = 0;
	int len = strlen(strIMEI);
	unsigned long genCode = 0;

	for(i = 0; i<len; i++)
	{
		genCode += strIMEI[i] * code1;
		genCode += strIMEI[i] * code2;
		genCode += strIMEI[i] * code3;
	}

	env->ReleaseStringUTFChars(imei, strIMEI);

	return genCode == regcode;
}

/*
 * Class:     com_wiseman_jxgl_Util
 * Method:    getRegisterCode
 * Signature: (Ljava/lang/String;)J
 */
JNIEXPORT jlong JNICALL Java_com_wiseman_jxgl_Util_getRegisterCode
  (JNIEnv *env, jclass cls, jstring imei){


		long  code1 = 19790314;
		long  code2 = 19811101;
		long  code3 = 20070828;
		const char *strIMEI = env->GetStringUTFChars(imei, 0);
		int i = 0;
		int len = strlen(strIMEI);
		unsigned long genCode = 0;

		for(i = 0; i<len; i++)
		{
			genCode += strIMEI[i] * code1;
			genCode += strIMEI[i] * code2;
			genCode += strIMEI[i] * code3;
		}

		env->ReleaseStringUTFChars(imei, strIMEI);

		return genCode;
}
